feat: chain manager with longest-chain fork resolution and state replay#33
feat: chain manager with longest-chain fork resolution and state replay#33arunabha003 wants to merge 27 commits intoStabilityNexus:mainfrom
Conversation
|
Caution Review failedFailed to post review comments WalkthroughIntroduces a complete blockchain implementation scaffold with core primitives (blocks, transactions, state, consensus), a fee-based mempool with nonce ordering, dynamic difficulty adjustment, canonical serialization, and comprehensive test coverage alongside build tooling. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant ChainManager as ChainManager
participant Block as Block
participant State as State
participant Mempool as Mempool
Client->>ChainManager: add_block(block)
ChainManager->>ChainManager: Check duplicate & known parent
ChainManager->>Block: Validate merkle root & coinbase
alt Block valid
ChainManager->>State: Replay state along candidate path
State-->>ChainManager: Updated state
ChainManager->>ChainManager: Validate consensus (PoW, difficulty)
ChainManager->>ChainManager: Decision: extend/reorg/fork
ChainManager->>ChainManager: Update canonical chain & tip
ChainManager->>Mempool: Remove confirmed transactions
ChainManager-->>Client: Return tx_id
else Block invalid
ChainManager-->>Client: Raise ChainValidationError
end
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly Related PRs
Suggested Labels
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Superseded by #34. Closing this PR to keep review history in one place. |
Addressed Issues:
Part of #8
Depends on #31
Summary
Validation
Checklist
AI Usage Disclosure
Check one of the checkboxes below:
I have used the following AI models and tools: TODO
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.
Summary by CodeRabbit
Release Notes
New Features
Chores
Tests